package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页数据
 */
public class OrderConfirmVo {
    //收获地址
    List<MemberAddressVo> address;

    //所有选中的购物项
    List<OrderItemVo> items;
    //发票记录

    //优惠卷信息
    /**积分*/
    private Integer integration;

    @Getter@Setter
    Map<Long,Boolean> stocks;
    //订单防重令牌
    @Getter@Setter
    String orderToken;

    public Integer getCount(){
        Integer i = 0;
        if(items != null) {
            for (OrderItemVo item : items) {
                 i += item.getCount();
            }
        }
        return i;
    }

    /*应付价格*/
    //BigDecimal payPrice;

    public List<MemberAddressVo> getAddress() {
        return address;
    }

    public void setAddress(List<MemberAddressVo> address) {
        this.address = address;
    }

    public List<OrderItemVo> getItems() {
        return items;
    }

    public void setItems(List<OrderItemVo> items) {
        this.items = items;
    }

    public Integer getIntegration() {
        return integration;
    }

    public void setIntegration(Integer integration) {
        this.integration = integration;
    }

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if(items != null) {
            for (OrderItemVo item : items) {
                BigDecimal itemPrice = item.getPrice();
                Integer itemCount = item.getCount();
                BigDecimal itemSum = itemPrice.multiply(new BigDecimal(itemCount));

                sum = sum.add(itemSum);
            }
        }
        return sum;
    }


    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
